using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace BlimpControlPanel
{
   public partial class GaugeControl : UserControl
   {
       private double degreesPerUnit = 0;

       public GaugeControl()
      {
         InitializeComponent();

         centerPoint = new Point(100, 100);
         degreesPerUnit = (max - min) / 360;

         this.Paint += new PaintEventHandler(this_Paint);
      }

      private Point centerPoint;

      private void this_Paint(object sender, PaintEventArgs e)
      {
         Pen pen = new Pen(Color.Green, 2.0F);
         e.Graphics.DrawArc(pen, 0, 0, 200, 200, 0, 360);
         e.Graphics.DrawLine(pen, centerPoint, GetPoint(DegreeToRadian(degreesPerUnit*currentValue), 100));

         // e.Graphics.DrawLine(pen, 100, 100, 150, 150);
         pen.Dispose();
      }

      private Point GetPoint(double angle, int hyp)
      {
         
         double y = centerPoint.Y - (hyp * Math.Sin(angle));
         double x = centerPoint.X + (hyp * Math.Cos(angle));

         return new Point((int)x, (int)y);
      }

      private double DegreeToRadian(double angle)
      {
         return Math.PI * angle / 180.0;
      }

       /// <summary>
       /// Current value to show on the gauge.
       /// </summary>
      public int Value
      {
          get { return currentValue; }
          set { currentValue = value; }
      }

      private int currentValue = 60;

       /// <summary>
       /// Maximum value possible for this control.
       /// </summary>
      public int MaxValue
      {
          get { return max; }
          set { 
              max = value;
              degreesPerUnit = (max - min) / 360;
          }
      }

       private int max = 360;

       /// <summary>
       /// Minimum value possible for this control.
       /// </summary>
       public int MinValue
       {
           get { return min; }
           set { 
               min = value;
               degreesPerUnit = (max - min) / 360;
           }
       }

       private int min = 0;
   }
}
